class ZigzagIterator(object):

    def __init__(self, v1, v2):
        """
        Initialize your data structure here.
        :type v1: List[int]
        :type v2: List[int]
        """
        self.v1 = v1
        self.v2 = v2
        self.index_1 = 0
        self.index_2 = 0
        self.state = 1
        self.n1 = len(self.v1)
        self.n2 = len(self.v2)

    def next(self):
        """
        :rtype: int
        """
        if self.state:
            if self.index_1 < self.n1:
                value = self.v1[self.index_1]
                self.index_1 += 1
                self.state = 0
                return value
            else:
                value = self.v2[self.index_2]
                self.index_2 += 1
                return value
        if not self.state:
            if self.index_2 < self.n2:
                value = self.v2[self.index_2]
                self.index_2 += 1
                self.state = 1
                return value
            else:
                value = self.v1[self.index_1]
                self.index_1 += 1
                return value


    def hasNext(self):
        """
        :rtype: bool
        """
        if self.index_1 == self.n1 and self.index_2 == self.n2:
            return False
        else:
            return True